package com.wlp.pengpicturebackend.model.enums;

import cn.hutool.core.util.ObjUtil;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public enum UserRoleEnum {
    USER("拥护", "user"),
    ADMIN("管理员", "admin");
    private final String text;
    private final String value;

    UserRoleEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    private static Map<String, UserRoleEnum> userRoleEnumMap;
    static {
        userRoleEnumMap = new HashMap<>();
        for (UserRoleEnum userRoleEnum : UserRoleEnum.values()) {
            userRoleEnumMap.put(userRoleEnum.value, userRoleEnum);
        }
    }


    /**
     * 根据值获取value
     *
     * @param value:
     * @Author: wlp
     * @Date: 2025/1/3 9:31
     * @return: com.wlp.pengpicturebackend.model.enums.UserRoleEnum
     **/
    public static UserRoleEnum getEnumByValue(String value) {
        if (ObjUtil.isEmpty(value)) {
            return null;
        }
        return userRoleEnumMap.get(value);
    }

}
